package cn.wolfcode.rbac.controller;

import cn.wolfcode.rbac.pojo.Department;
import cn.wolfcode.rbac.pojo.Employee;
import cn.wolfcode.rbac.service.DepartmentService;
import cn.wolfcode.rbac.service.impl.DepartmentServiceImpl;
import cn.wolfcode.rbac.util.PageResult;
import cn.wolfcode.rbac.util.QueryObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/department")
@Controller
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;

    @RequestMapping("/list")
    public String selectall(Model model, QueryObject queryObject) {
//        手写分页
//         PageResult pageResult = departmentService.PageResult(queryObject);
//         model.addAttribute("pageResult",pageResult);
//        插件
        PageInfo<Department> pageInfo = departmentService.getallemp(queryObject);
        model.addAttribute("pageResult", pageInfo);
        return "department/list";
    }

    @RequestMapping("/input")
    public String input(Integer id, Model model) {
        if (id != null) {
            Department department = departmentService.selectbyid(id);
            model.addAttribute("d", department);
        }
        return "department/input";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Department department) {
        //保存或修改
        departmentService.save(department);
        return "redirect:/department/list";
    }

    @RequestMapping("/delete")
    public String delect(Integer id) {
        departmentService.delect(id);
        return "redirect:/department/list";
    }

}
